Learn R Programming

collapse (version 1.1.0)

pwcor, pwcov, pwNobs: Pairwise Correlations, Covariances and Observation Count

Description

Computes pairwise Pearsons correlations, covariances and observation counts. Pairwise correlations and covariances can be computed together with observation counts and p-values, and output as 3D array (default) or list of matrices. For an equivalent and faster implementation of pwcor see Hmisc::rcorr (written in Fortran). A major feature of pwcor and pwcov is their sophisticated print method.

Usage

pwcor(X, ..., N = FALSE, P = FALSE, array = TRUE)

pwcov(X, ..., N = FALSE, P = FALSE, array = TRUE)

pwNobs(X)

# S3 method for pwcor print(x, digits = 2L, sig.level = 0.05, show = c("all","lower.tri","upper.tri"), spacing = 1L, ...)

# S3 method for pwcov print(x, digits = 2L, sig.level = 0.05, show = c("all","lower.tri","upper.tri"), spacing = 1L, ...)

Arguments

X

a matrix or data.frame, for pwcor and pwcov all columns must be numeric.

x

an object of class 'pwcor' / 'pwcov'.

N

logical. TRUE also computes pairwise observation counts.

P

logical. TRUE also computes pairwise p-values (same as cor.test).

array

logical. If N = TRUE or P = TRUE, TRUE (default) returns output as 3D array whereas FALSE returns a list of matrices.

digits

integer. The number of digits to round to in print.

sig.level

numeric. P-value threshold below which a '*' is displayed above significant coefficients if P = TRUE.

show

character. The part of the correlation / covariance matrix to display.

spacing

integer. Controls the spacing between different reported quantities in the printout of the matrix: 0 - compressed, 1 - single space, 2 - double space.

...

other arguments passed to cor or cov. Only sensible if P = FALSE.

Value

a numeric matrix, 3D array or list of matrices of the computed statistics. For pwcor and pwcov the object has a class 'pwcor' and 'pwcov', respectively.

See Also

qsu, Collapse Overview

Examples

Run this code
# NOT RUN {
mna <- na_insert(mtcars)
pwcor(mna)
pwcov(mna)
pwNobs(mna)
pwcor(mna, N = TRUE)
pwcor(mna, P = TRUE)
pwcor(mna, N = TRUE, P = TRUE)
aperm(pwcor(mna, N = TRUE, P = TRUE))
print(pwcor(mna, N = TRUE, P = TRUE), digits = 3, sig.level = 0.01, show = "lower.tri")
pwcor(mna, N = TRUE, P = TRUE, array = FALSE)
print(pwcor(mna, N = TRUE, P = TRUE, array = FALSE), show = "lower.tri")


# }

Run the code above in your browser using DataLab